<template>
  <div class="app-container">
      <h1>模拟API调用</h1><hr/>
        酒店编号 10001	测试md5数据 77c86f21f692b5133eac387dd30c1659
        <hr/>
        <el-form label-width="80px">
        <div v-if="!passok">
        <el-form-item label="签名密钥">
            <el-input v-model="obj.signKey"></el-input>
        </el-form-item>
        <el-form-item label="酒店编号">
            <el-input v-model="obj.zkcode"></el-input>
        </el-form-item>
         <el-form-item>
            <el-button type="primary" @click="signKey">发送签名校验</el-button>
            <el-button @click="reset">重置</el-button>
        </el-form-item>
        </div>

      
        <div v-if="passok">
        <el-form-item label="上传酒店数据">
            <el-input type="textarea" v-model="hotel1" cols="15" rows="15"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="updatas">立即上传</el-button>
        </el-form-item>

         <el-form-item label="获取酒店数据">
            <el-input type="textarea" v-model="hotel2" cols="15" rows="15"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="get">立即获取</el-button>
        </el-form-item>
        </div>
        </el-form>
  </div>

   
</template>


<script>
import hotelapi from './api/hotelapi'

export default {
    data() {

      return {
        passok: 0,
        obj: {
   
        },
        hotel1:{

        },
        hotel2:{

        },
      }
     
    },
    created() {
    
    },
    activated: function(){
      this.passok= 0;
    },
   methods: {
        get(){
            hotelapi.hotel(this.obj).
            then(({data}) => {
                 this.$message({
                  type: 'success',
                  message: '获取成功!'
               })
            this.hotel2 = JSON.stringify(data.data);
             
            })
       },
       updatas(){
            var obj = JSON.parse(this.hotel1);
            hotelapi.saveHotel(obj).
            then((response) => {
                 this.$message({
                  type: 'success',
                  message: '添加成功!'
               })
               this.$router.push({path:'/hotel-hotel'})
            })
       },
       signKey(){
           hotelapi.getHotelSignKey(this.obj)
            .then(Response =>{
                this.passok=1;
            })  
       },
       reset(){
           this.obj={};
       }
   }

}

</script>
